<script setup lang="ts" name="TomatoSetTime">
import MenuBar from '@/views/components/menuBar/index.vue'
import { sendTabMessage } from '@/utils/windowTool'
const { proxy } = getCurrentInstance() as ComponentInternalInstance;

//本模块设置数据
const time = ref<number>(1)

//IPC事件
const ipcs = {
    //获取番茄钟的设置数据
    getConfig: () => {
        const { module, value } = window.ipcRenderer.sendSync('STORAGE-GET', { module: 'tomato' })
        //如果所属本模块，更新模块设置数据
        if (module == 'tomato') {
            time.value = value.time
        }
    },
    saveData: () => {
        const data = { time: time.value }
        window.ipcRenderer.sendSync('STORAGE-SAVE', { module: 'tomato', data })
    },
    closeModal: () => {
        window.ipcRenderer.send('GENERAL-BAR-OPERATE', { mark: 'close' })
    }
}


//监听保存时间
const handleSettingSave = () => {
    //保存时间
    ipcs.saveData()
    sendTabMessage('setTime')
    ipcs.closeModal()
}

onMounted(() => {
    ipcs.getConfig()
})

</script>
<template>
    <MenuBar title="设置计时时长" barColor="#222" hideMaximize hideMinimize :logo="{ isIcon: true, value: 'times' }" />
    <div class="main-content tomato-set-time">
        <el-input-number v-model="time" :min="1" :max="99"></el-input-number>
        <el-button class="m-r-5-0" @click="handleSettingSave" type="primary">保存</el-button>
    </div>
</template>
<style lang="scss">
.main-content.tomato-set-time {
    width: 100%;
    height: calc(100% - 40px);
    background-color: #000;
    display: flex;
    justify-content: center;
    align-items: center;
}
</style>
<style lang="scss" scoped></style>
